import { isJson } from "./validate";
const appPrefix = 'advisory_company_'
export const getLocalStorage = (key: string) => {
  const value: any = localStorage.getItem(`${appPrefix}${key}`);
  if (value && isJson(value)) {
    return JSON.parse(value);
  } else {
    return false;
  }
};

//  设置缓存
export const getLocalStorageCache = (key: string) => {
  let value;
  try {
    value = JSON.parse(localStorage.getItem(`${appPrefix}${key}`) as any);
  } catch {
    value = "";
  }
  return value;
};

//  设置缓存
export const setLocalStorageCache = (key: string, value: any) => {
  localStorage.setItem(`${appPrefix}${key}`, JSON.stringify(value));
};

//  设置缓存
export const removeLocalStorageCache = (key: string) => {
  localStorage.removeItem(`${appPrefix}${key}`);
};

//  清空缓存
export const clearLocalStorageCache = () => {
  localStorage.clear();
};
